package com.xzwk.subject.domain.servcie.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xzwk.subject.domain.convert.SubjectInfoConverter;
import com.xzwk.subject.domain.convert.SubjectLabelConverter;
import com.xzwk.subject.domain.dto.SubjectLabelDTO;
import com.xzwk.subject.domain.entity.SubjectAnswerBO;
import com.xzwk.subject.domain.entity.SubjectInfoBO;
import com.xzwk.subject.domain.entity.SubjectLabelBO;
import com.xzwk.subject.domain.handler.subject.SubjectTypeHandler;
import com.xzwk.subject.domain.handler.subject.SubjectTypeHandlerFactory;
import com.xzwk.subject.domain.request.SaveSubjectInfoRequest;
import com.xzwk.subject.domain.servcie.SubjectInfoDomainService;
import com.xzwk.subject.domain.servcie.SubjectLabelDomainService;
import com.xzwk.subject.infra.basic.entity.SubjectInfo;
import com.xzwk.subject.infra.basic.entity.SubjectLabel;
import com.xzwk.subject.infra.basic.entity.SubjectMapping;
import com.xzwk.subject.infra.basic.service.SubjectInfoService;
import com.xzwk.subject.infra.basic.service.SubjectMappingService;
import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
public class SubjectInfoDomainServiceImpl implements SubjectInfoDomainService {

  @Resource
  private SubjectInfoService subjectInfoService;
  @Resource
  private SubjectInfoConverter subjectInfoConverter;

  @Resource
  private SubjectTypeHandlerFactory subjectTypeHandlerFactory;

  @Override
  public void add(SaveSubjectInfoRequest request) {
    SubjectInfoBO subjectInfoBO= subjectInfoConverter.toSubjectInfoBO(request);

    List<SubjectAnswerBO> subjectAnswerBOList=subjectInfoConverter.toSubjectAnswerBO(request.getOptionList());
    subjectInfoBO.setOptionList(subjectAnswerBOList);

    //工厂+策略
    //一个工厂 包含了4种类型,根据传入的去选择生成的类型

    SubjectInfo subjectInfo=subjectInfoConverter.boToSubjectInfo(subjectInfoBO);
    subjectInfoService.save(subjectInfo);
    SubjectTypeHandler handler = subjectTypeHandlerFactory.getHandler(subjectInfo.getSubjectType());
    handler.add(subjectInfoBO);


  }



  @Override
  public Object page(Page<SubjectLabel> page, QueryWrapper<SubjectLabel> subjectLabelQueryWrapper) {
    return null;
  }

  @Override
  public SubjectLabelDTO getById(Serializable id) {
    return null;
  }

  @Override
  public Boolean save(SaveSubjectInfoRequest request) {
    return null;
  }

  @Override
  public Boolean updateById(SubjectLabelBO subjectLabel) {
    return null;
  }

  @Override
  public Boolean removeByIds(List<Long> idList) {
    return null;
  }

  @Override
  public List<SubjectLabelBO> queryPrimaryLabel(Long parentId) {
    return null;
  }

  @Override
  public List<SubjectLabelDTO> queryLabelByCategoryId(Long categoryId) {
    return null;
  }
}
